package com.study.experiment05.bean;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;

public class NewUser {
    private String username;
    private String password;
    private DBConn conn;
    private String sql;

    public NewUser() {

    }

    public NewUser(String name, String password) {
        this.username = name;
        this.password = password;
        System.out.println("username:" + username + " password:" + password);
        conn = new DBConn();
        sql = "insert into tab_user(name,pwd) values('" + username + "','" + password + "')";
    }

    public int AddNewUser() {
        Connection connection = conn.getConn();
        Statement st;
        try {
            st = connection.createStatement();
            return st.executeUpdate(sql);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return -1;
    }
}
